#!/bin/sh

ip=$1
user=$2
passwd=$3
action=$4

if [ "x$4" == "xstart" ]; then
    echo "start cmd"
    expect -c "
    spawn ssh $user@$ip \"cd /root/client && /bin/bash start.sh\"
    expect {
    \"*assword\" {set timeout 300; send \"$passwd\n\";}
    }
    expect eof" &
fi

if [ "x$4" == "xkill" ]; then
    echo "kill cmd"
    expect -c "
    spawn ssh $user@$ip \"ps -ef | grep RpcTest | grep -v grep | cut -c 9-15 | xargs kill -s 9\"
    expect {
    \"*assword\" {set timeout 300; send \"$passwd\n\";}
    }
    expect eof"
fi
